import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;

public class TransportClientPool {

	public static TransportClient[] transportClients;
	public static String hostName = "localhost";
	private int TransportClientConnections = 0;
	private int PoolSize = 1;

	public TransportClientPool(int PoolSize) {
		this.PoolSize = PoolSize;
		Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.sniff", true).put("client", true).put("data", false)
				.put("clusterName", "elasticsearch").build();
		transportClients = new TransportClient[PoolSize];		
		for (int i = 0; i < PoolSize; i++) {
			transportClients[i] = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(hostName, 9300));
		}

	}

	public TransportClient getTransportClient() {
		TransportClientConnections++;
		return transportClients[TransportClientConnections / PoolSize];
	}

	public SearchResponse Query(SearchRequestBuilder searchRequestBuilder) {

		return searchRequestBuilder.execute().actionGet();
	}

	public BulkResponse Query(BulkRequestBuilder bulkRequestBuilder) {

		return bulkRequestBuilder.execute().actionGet();
	}

}
